/* Alan Fortes
 *
 * Design Assignment 0
 *
 * 2/7/15
*/

.org 00

ldi r16, 55 //Each number to be added up is loaded into a register.
ldi r17, 47
ldi r18, 46
ldi r19, 38
ldi r20, 41

add r16, r17  //The five numbers are added up in register r16.
add r16, r18
add r16, r19
add r16, r20

cpi r16, 128      //The sum is compared to 128 to detect for an overflow.             
brsh setPortBHigh //If the sum is equal to or higher than 128, an overflow is  
                  //is detected, and the program will branch to set PORTB.2 high.  
rjmp setPortBLow  //If an overflow is absent, the program will set PORTB.2 low.

SetPortBHigh:
sbi PORTB, 2      //PortB.2 is driven high, if an overflow is detected.
rjmp endProgram   //The program then terminates  after this has been accomplished.

setPortBLow:
cbi PORTB, 2      //PORTB.2 is driven low, if there is no overflow

endProgram:
ldi r21, 0 //The purpose of this instruction is to stop the program
		   //after all of the desired instructions have been executed, 
		   //so that we may see what the number of cycles and run time
		   //are, just after the last pertinent instruction has been run.